using System;
using System.Collections.Generic;
using System.Text;
using NUnit.Framework;
using dnAnalytics.Math;

namespace dnAnalytics.UnitTests
{
    public static class TestHelper
    {
        public static void TestRelativeError(Complex expected, Complex approx, double acceptableError)
        {
            TestRelativeError(expected.Real, approx.Real, acceptableError);
            TestRelativeError(expected.Imaginary, approx.Imaginary, acceptableError);
        }

        public static void TestRelativeError(double expected, double approx, double acceptableError)
        {
            double relativeError;
            if (System.Math.Abs(expected) < 1e-13)
            {
                relativeError = System.Math.Abs(approx - expected);
            }
            else
            {
                relativeError = System.Math.Abs((approx - expected) / expected);
            }
            Assert.Less(relativeError, acceptableError);
        }
    }
}
